package day13;

import java.io.*;

public class iotest01 {
    public static void main(String[] args) throws IOException {
//        File file=new File("G:\\ready\\a\\a.txt");
//        System.out.println(file.createNewFile());
//        method();//测试普通字节流输出
//        method1();//测试高效字节流输出
//        method2();//测试普通字节流输入
//        method3();//测试高效字节流输入
//        method4();//测试普通字符流输出
//        method5();//测试高效字符流输出
//        method6();//测试普通字符流输入
        method7();//测试高效字符流输入
    }

    private static void method7() {
        Reader in=null;
        try {
            in =new BufferedReader(new FileReader("G:\\ready\\a\\a.txt"));
            int b;
            while ((b=in.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method6() {
        Reader in=null;
        try {
            in=new FileReader("G:\\ready\\a\\a.txt");
            int b;
            while ((b= in.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method5() {
        Writer out=null;
        try {
            out =new BufferedWriter(new FileWriter("G:\\ready\\a\\a.txt",true));
            out.write(101);
            out.write(101);
            out.write(101);
            out.write(101);
            out.write(101);
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method4() {
        Writer out=null;
        try {
            out=new FileWriter("G:\\ready\\a\\a.txt");
            out.write(100);
            out.write(100);
            out.write(100);
            out.write(100);
            out.write(100);
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method3() {
        InputStream in=null;
        try {
            in=new BufferedInputStream(new FileInputStream("G:\\ready\\a\\a.txt"));
            int b;
            while ((b=in.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method2() {
        InputStream in=null;
        try {
            in =new FileInputStream("G:\\ready\\a\\a.txt");
            int b;
            while ((b=in.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        OutputStream out=null;
        try {
            out=new BufferedOutputStream(new FileOutputStream("G:\\ready\\a\\a.txt",true));
            out.write(101);
            out.write(102);
            out.write(103);
            out.write(104);
            out.write(105);
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method() {
        OutputStream out=null;
        try {
            out=new FileOutputStream("G:\\ready\\a\\a.txt");
            out.write(98);
            out.write(99);
            out.write(100);
            out.write(101);
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
